我对 Git 存储库中的两个文件进行了多次更改(特别是添加了两个公式来 brew)。
我单独提交了更改:
git commit file1 git commit file2
然后我对 GitHub 做了一次推送:
git push git@github.com:myname/homebrew.git
我现在想向上游存储库发送两个拉取请求,一个用于 file1,一个用于 file2。这可能吗?
如果您在同一个提交中更改了两个文件,那么不,这是不可能的。推送和拉取操作在提交级别;他们不会把它们分开。
如果您还没有共享更改,您可以将提交分成两部分,为每部分创建一个分支,然后为这些提交拉取请求。
这是有很多方法可以做的事情之一,但是例如,您可以执行以下操作:
# make sure the commit in question is the most recent # make branch to point to the previous commit, leaving the changes in your work tree git reset HEAD^ # commit the changes to the first file git add file1 git commit # make a branch for the first commit git branch first-branch HEAD^ # commit the changes to the second file git add file2 git commit # create and check out a branch for this commit git checkout -b second-branch # rebase the branch back, so that it doesn't include the first commit git rebase --onto HEAD^^ HEAD^ second-branch # point your master branch somewhere that makes sense - maybe before either branch git checkout master git reset --hard first-branch^
这会给你留下这样的历史:
- x (master) - A (first-branch) \ - B (second-branch)
其中commit A 修改了file1,commit B 修改了file2。
一旦历史看起来像你喜欢的那样,你可以分别推送两个分支并做你需要做的事情:
git push origin first-branch second-branch